;  cheap water pixel shader used by A3DTerrainWater. 

; t1, ground base map
; t2, reflect map, alpha channel of which is the edge alpha value
; t3, reflect vector in world space, packed to [0.0, 1.0]

ps.1.4

def c1, 0.25, 0.2, 0.0, 0.6
def c2, 0.0, 0.0, 0.0, 1.0
def c3, 0.85, 0.85, 0.85, 1.0
def c6, 0.0, 1.0, 0.0, 1.0


texcrd	r2.xy, t2_dw.xyw

mov r2.b, c3.a

phase

texld	r1, t1
texld 	r2, r2
texld	r0, t3			// camera space reflect vector transformed into world space, with normalization (packed)

// calculate fresnel effects : R0 + (1-R0) (1-cos(q))^5
dp3_sat r3.rgba, r0_bx2, c6

mul r0.a, 1-r3.a, 1-r3.a			// squared
mul r0.a, r0.a, r0.a				// quartic
mul_sat r0.a, r0.a, 1-r3.a			// quintic

lrp r0.a, r0.a, c2.a, c1.a

mul r0.a, r0.a, r1.a
lrp r0.rgb, r0.a, r2, r1
// mul r0.rgb, r2, r0.a
+mov r0.a, c3.a	

